package tuan.core.extract;

import java.util.*;

public class Product {
	public String url = "";
	public String title = "";
	public String nowPrice = "";
	public String oldPrice = "";
	public String savePrice = "";
	public String buyNum = "";
	public String imgUrl = "";
	public String discount = "";
	public boolean isEnd = false;

	public boolean fetchOk = true;

	public List<String> imgList = new ArrayList<String>();
	public List<String> addrList = new ArrayList<String>();
	public String content;

	public String toString() {
		return String.format("原始网址:%s\n图片:%s\n标题:%s\n现价:%s\n原价:%s\n节省:%s\n购买人数:%s\n是否已结束:%s\n折扣:%s\n\n",url,imgUrl,title,nowPrice,oldPrice,savePrice,buyNum,isEnd,discount);
	}

	public String toHtml() {
		String text = "";
		if (!fetchOk) {
			text = "<br>出错了<br><table 'color:red'>";
		} else {
			text = "<table 'color:green'>";
		}
		text += String.format("<tr><td>url</td><td><a href='%s'>%s</a></td></tr>", url,url);
		text += String.format("<tr><td>imgUrl</td><td><a href='%s'><img src='%s'/></a></td></tr>", imgUrl,imgUrl);
		text += String.format("<tr><td>title</td><td>%s</td></tr>", title);
		text += String.format("<tr><td>nowPrice</td><td>%s</td></tr>", nowPrice);
		text += String.format("<tr><td>oldPrice</td><td>%s</td></tr>", oldPrice);
		text += String.format("<tr><td>savePrice</td><td>%s</td></tr>", savePrice);
		text += String.format("<tr><td>buyNum</td><td>%s</td></tr>", buyNum);
		text += String.format("<tr><td>isEnd</td><td>%s</td></tr>", isEnd);
		text += String.format("<tr><td>discount</td><td>%s</td></tr>", discount);
		//text += String.format("<tr><td>content</td><td>%s</td></tr>", content);		 
		String imgListHtml = "";
		for (String img : imgList) {
			imgListHtml += String.format("<img src='%s'/>",img);
		}
		text += String.format("<tr><td>imgList</td><td>%s</td></tr>", imgListHtml);
		String addrListHtml = "";
		for (String addr : addrList) {
			addrListHtml += addr + "<br>";
		}
		text += String.format("<tr><td>addrList</td><td>%s</td></tr>", addrListHtml);
		text += "</table><br><br>\n";
		return text;

	}

	public void save() {
		System.out.println(toHtml());
	}

}
